import { assetTypeMap, diskTypeMap, zoneMap, envMap } from '@/views/cmdb/config'

export const esAssetColumns = _this => [
  {
    title: 'IP地址',
    key: 'business_ip',
    minWidth: 120,
    fixed: 'left',
    render: (h, { row }) => {
      return <router-link to={'/cmdb/asset/' + row.assets.id} style='color: #2d8cf0'>{row.assets.businessIp}</router-link>
    }
  },
  {
    title: '主机名',
    key: 'hostname',
    minWidth: 150,
    render: (h, { row }) => {
      return <span>{row.assets.hostname}</span>
    }
  },
  {
    title: '资产类型',
    key: 'asset_type',
    width: 120,
    render: (h, { row }) => {
      return <Tag color={assetTypeMap[row.assets.assetType].color}>{assetTypeMap[row.assets.assetType].name}</Tag>
    }
  },
  {
    title: 'CPU(核)',
    key: 'cpu',
    width: 80,
    render: (h, { row }) => {
      if (row.assets.cpu) {
        return <span>{row.assets.cpu}</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '内存(G)',
    key: 'memory',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.memory) {
        return <span>{row.assets.memory
        }</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '硬盘(T)',
    key: 'disk',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.diskType && row.assets.diskSize) {
        return <span>{diskTypeMap[row.assets.diskType].name}:{row.assets.diskSize}T</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '环境',
    key: 'env',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={envMap[row.assets.env].color}>{envMap[row.assets.env].name}</Tag>
    }
  },
  {
    title: '区域',
    key: 'zone',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={zoneMap[row.assets.zone].color}>{zoneMap[row.assets.zone].name}</Tag>
    }
  },
  {
    title: '创建时间',
    key: 'create_time',
    minWidth: 120,
    maxWidth: 120,
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.assets.createTime}</span>
    }
  },
  {
    title: '更新时间',
    key: 'update_time',
    sortable: true,
    minWidth: 120,
    maxWidth: 120,
    render: (h, { row }) => {
      return <span>{row.assets.updateTime}</span>
    }
  },
  {
    title: '操作',
    key: 'operate',
    minWidth: 200,
    maxWidth: 300,
    fixed: 'right',
    render: (h, { row }) => {
      return <div>
        <el-tooltip className='item' effect='dark' content='移出集群' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.showRelatedAssetModal = true
              _this.changeAssetIds = [row.assets.id]
              _this.action.type = 'remove'
              _this.action.title = '移出'
            }} size='small' type='danger'>移出集群
          </el-link>
        </el-tooltip>
        <el-divider direction='vertical' />
        <el-tooltip className='item' effect='dark' content='连通测试' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.pingAliveCheckAsset(row.assets.id)

              // _this.showServiceDeleteModal = true
              // _this.serviceInfo = row
            }} size='small' style='font-size:13px;' type='success'>连通测试
          </el-link>
        </el-tooltip>
      </div>
    }
  }
]

export const dfsAssetColumns = _this => [
  {
    title: 'IP地址',
    key: 'business_ip',
    fixed: 'left',
    render: (h, { row }) => {
      return <router-link to={'/cmdb/asset/' + row.assets.id} style='color: #2d8cf0'>{row.assets.businessIp}</router-link>
    }
  },
  {
    title: '主机名',
    key: 'hostname',
    render: (h, { row }) => {
      return <span>{row.assets.hostname}</span>
    }
  },
  {
    title: '资产类型',
    key: 'asset_type',
    width: 120,
    render: (h, { row }) => {
      return <Tag color={assetTypeMap[row.assets.assetType].color}>{assetTypeMap[row.assets.assetType].name}</Tag>
    }
  },
  {
    title: 'CPU(核)',
    key: 'cpu',
    width: 80,
    render: (h, { row }) => {
      if (row.assets.cpu) {
        return <span>{row.assets.cpu}</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '内存(G)',
    key: 'memory',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.memory) {
        return <span>{row.assets.memory
        }</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '硬盘(T)',
    key: 'disk',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.diskType && row.assets.diskSize) {
        return <span>{diskTypeMap[row.assets.diskType].name}:{row.assets.diskSize}T</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '环境',
    key: 'env',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={envMap[row.assets.env].color}>{envMap[row.assets.env].name}</Tag>
    }
  },
  {
    title: '区域',
    key: 'zone',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={zoneMap[row.assets.zone].color}>{zoneMap[row.assets.zone].name}</Tag>
    }
  },
  {
    title: '角色',
    key: 'topology_role',
    minWidth: 200,
    maxWidth: 400,
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.topologyRole}</span>
    }
  },
  // {
  //   title: '创建时间',
  //   key: 'create_time',
  //   width: 140,
  //   sortable: true,
  //   render: (h, { row }) => {
  //     return <span>{row.assets.createTime}</span>
  //   }
  // },
  // {
  //   title: '更新时间',
  //   key: 'update_time',
  //   width: 140,
  //   sortable: true,
  //   render: (h, { row }) => {
  //     return <span>{row.assets.updateTime}</span>
  //   }
  // },
  {
    title: '操作',
    key: 'operate',
    width: 200,
    fixed: 'right',
    render: (h, { row }) => {
      return <div>
        <el-tooltip className='item' effect='dark' content='移出集群' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.showRelatedAssetModal = true
              _this.changeAssetIds = [row.assets.id]
              _this.action.type = 'remove'
              _this.action.title = '移出'
            }} size='small' type='danger'>移出集群
          </el-link>
        </el-tooltip>
        <el-divider direction='vertical' />
        <el-tooltip className='item' effect='dark' content='连通测试' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              // _this.showServiceDeleteModal = true
              // _this.serviceInfo = row
              _this.pingAliveCheckAsset(row.assets.id)
            }} size='small' style='font-size:13px;' type='success'>连通测试
          </el-link>
        </el-tooltip>
      </div>
    }
  }
]

export const redisAssetColumns = _this => [
  {
    title: 'IP地址',
    key: 'business_ip',
    fixed: 'left',
    render: (h, { row }) => {
      return <router-link to={'/cmdb/asset/' + row.assets.id} style='color: #2d8cf0'>{row.assets.businessIp}</router-link>
    }
  },
  {
    title: '主机名',
    key: 'hostname',
    render: (h, { row }) => {
      return <span>{row.assets.hostname}</span>
    }
  },
  {
    title: '资产类型',
    key: 'asset_type',
    width: 120,
    render: (h, { row }) => {
      return <Tag color={assetTypeMap[row.assets.assetType].color}>{assetTypeMap[row.assets.assetType].name}</Tag>
    }
  },
  {
    title: 'CPU(核)',
    key: 'cpu',
    width: 80,
    render: (h, { row }) => {
      if (row.assets.cpu) {
        return <span>{row.assets.cpu}</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '内存(G)',
    key: 'memory',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.memory) {
        return <span>{row.assets.memory
        }</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '硬盘(T)',
    key: 'disk',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.assets.diskType && row.assets.diskSize) {
        return <span>{diskTypeMap[row.assets.diskType].name}:{row.assets.diskSize}T</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '环境',
    key: 'env',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={envMap[row.assets.env].color}>{envMap[row.assets.env].name}</Tag>
    }
  },
  {
    title: '区域',
    key: 'zone',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={zoneMap[row.assets.zone].color}>{zoneMap[row.assets.zone].name}</Tag>
    }
  },
  // {
  //   title: '创建时间',
  //   key: 'create_time',
  //   maxWidth: 120,
  //   sortable: true,
  //   render: (h, { row }) => {
  //     return <span>{row.assets.createTime}</span>
  //   }
  // },
  // {
  //   title: '更新时间',
  //   key: 'update_time',
  //   maxWidth: 120,
  //   sortable: true,
  //   render: (h, { row }) => {
  //     return <span>{row.assets.updateTime}</span>
  //   }
  // },
  {
    title: '操作',
    key: 'operate',
    fixed: 'right',
    minWidth: 200,
    render: (h, { row }) => {
      return <div>
        <el-tooltip className='item' effect='dark' content='移出集群' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.showRelatedAssetModal = true
              _this.changeAssetIds = [row.assets.id]
              _this.action.type = 'remove'
              _this.action.title = '移出'
            }} size='small' type='danger'>移出集群
          </el-link>
        </el-tooltip>
        <el-divider direction='vertical' />
        <el-tooltip className='item' effect='dark' content='连通测试' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              // _this.showServiceDeleteModal = true
              // _this.serviceInfo = row
              _this.pingAliveCheckAsset(row.assets.id)
            }} size='small' style='font-size:13px;' type='success'>连通测试
          </el-link>
        </el-tooltip>
      </div>
    }
  }
]
